package main

import (
	"fmt"
	"time"
)

func makeBuns(filling string, buns chan string) {
	fmt.Printf("开始做%s馅的包子\n", filling)
	fmt.Printf("开始剁%s馅的包子\n", filling)
	fmt.Printf("开始擀%s馅的包子\n", filling)
	time.Sleep(time.Second * 1)
	fmt.Printf("开始蒸%s馅的包子\n", filling)
	//上菜
	//把包好的包子放到通道内
	buns <- filling
	fmt.Printf("%s馅的包子已经放在通道内，时间%s\n", filling, time.Now())

}

func main() {

	//定义一个通道，用来存放包子
	buns := make(chan string)

	fillings := []string{"猪肉", "牛肉", "鸡肉"}

	for _, v := range fillings {
		go makeBuns(v, buns)

		//主程序不会等待协程执行完毕，直接往下执行

	}

	for i := 0; i < len(fillings); i++ {
		bun := <-buns
		fmt.Printf("上菜%s馅的包子+时间：%s\n", bun, time.Now())
	}
	//go 的通道也是一种类型，channel1 := make(chan 类型)就可以声明一个通道
	// 发送数据 channel1 <- "数据1"
	// 取数据 data := <- channel1
}
